package com.snail.controller;

import com.snail.model.dto.cart.RefundApplyDTO;
import com.snail.model.pojo.cart.BizRefundRequest;
import com.snail.model.vo.cart.RefundVO;
import com.snail.result.Result;
import com.snail.service.BizRefundRequestService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 退款控制器
 */
@RestController
@RequestMapping("/refund")
public class BizRefundRequestController {

    @Autowired
    private BizRefundRequestService bizRefundRequestService;

    /**
     * 提交退款申请
     */
    @PostMapping("/applyRefund")
    public Result<RefundVO> applyRefund(@Valid @RequestBody RefundApplyDTO applyDTO) {
        RefundVO refundVO = bizRefundRequestService.applyRefund(applyDTO);
        return Result.success(refundVO);
    }

    /**
     * 根据用户id查询当前用户的退款申请
     */
    @GetMapping("/getRefundRequestByUserId")
    public Result getRefundRequestByUserId(Long userId) {
          List<BizRefundRequest> refundRequests = bizRefundRequestService.getRefundRequestByUserId(userId);
        return Result.success(refundRequests);
    }

    /**
     * 修改退款申请
     */
    @PutMapping("/updateRefundRequest")
    public void updateRefundRequest(BizRefundRequest refundRequest) {
        bizRefundRequestService.updateRefundRequest(refundRequest);
    }

    /**
     * 撤销退款申请
     */
    @PutMapping("/quitRefundRequest")
    public void quitRefundRequest(Long userId, Integer status) {
        bizRefundRequestService.quitRefundRequest(userId, status);
    }
}
